/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/logisticsService.ts" />
/// <reference path="../src/tms.ts" />

describe('getLogisticsList',() => {
    var injector:ng.auto.IInjectorService;
    var service:ILogisticsService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<ILogisticsService>('logisticsService');
    });

    //常规无条件获取
    it('get logistics list normal',(done) => {
        service.getList(null, null, null, null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||||0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取单位名包含 物流 的物流方列表
    it('get logistics list by name \'物流\'',(done) => {
        service.getList('物流',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("物流||||0|10"); 
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取所属省份包含 江苏 的物流方列表
    it('get logistics list by province \'江苏\'',(done) => {
        service.getList(null,'江苏',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|江苏|||0|10"); 
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取所属城市包含 镇江丹阳市 的物流方列表
    it('get logistics list by city \'镇江丹阳市\' ',(done) => {
        service.getList(null,null,'镇江丹阳市',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("||镇江丹阳市||0|10"); 
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取所属区包含 无 的物流方列表
    it('get logistics list by area \'无 \'',(done) =>{
        service.getList(null,null,null,'无',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("|||无|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 单位名包含 物流 ,所属省份包含 江苏,所属城市包含 镇江丹阳市,所属区包含 无 物流方列表
    it('get logistics list by name \'物流\' and province \'江苏\' and city \'镇江丹阳市\' and  area \'无 \' ',(done) =>{
        service.getList('物流','江苏','镇江丹阳市','无',0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe("物流|江苏|镇江丹阳市|无|0|10");
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取物流方详情
    it('get detail ',(done)=>{
        service.getDetail('1').then((res)=>{
            expect(res.data.name).toBe("detail");
            expect(res.data.province).toBe("江苏");
            expect(res.data.city).toBe("镇江");
            expect(res.data.area).toBe("京口区");
            expect(res.data.address).toBe("学府路301号");
            expect(res.data.phoneNumber).toBe("133");
            expect(res.data.adminName).toBe("杨杨");
            expect(res.data.isEnabled).toBe(true);
            expect(res.data.extData).toBe("1");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加物流方
    it('add logistics',(done)=>{
        service.add('测试物流','江苏','镇江','京口区','学府路301号','3333','18352868111','123333','123333',false).then((res)=>{
            expect(res.data.extData).toBe("测试物流|江苏|镇江|京口区|学府路301号|3333|18352868111|123333|123333|false");
            done();
        },(err)=>{
            done.fail(err);
        });
    });
    
    //编辑物流方
    it('edit logistics',(done)=>{
        service.edit('1','测试物流','江苏','镇江','润州区','万达广场','18352868111','123321','123321',false).then((res)=>{
            expect(res.data.extData).toBe("1|测试物流|江苏|镇江|润州区|万达广场|18352868111|123321|123321|false");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除物流方
    it('delete logistics',(done)=>{
        service.delete('2').then((res)=>{
            expect(res.data.extData).toBe("2");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


});